package javaDemo14.JDBC;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class BrandTest {
    public static void main(String[] args) throws Exception {
        String brandName = "香飘飘";
        String companyName = "香飘飘奶茶有限公司";
        Integer ordered = 100;
        String description = "卖出的奶茶可绕地球三圈半";
        Integer status = 1;

        Properties prop = new Properties();

        prop.load(new FileInputStream("C:\\Users\\zx\\IdeaProjects\\JAVAbase\\src\\javaDemo14\\JDBC\\druid.properties"));

        DataSource ds = DruidDataSourceFactory.createDataSource(prop);

        Connection conn = ds.getConnection();

//        String sql = "SELECT * FROM tb_brand;";
        String sql = "insert into tb_brand(brand_name,company_name,ordered,description,status)values(?,?,?,?,?);";

        PreparedStatement prep = conn.prepareStatement(sql);

        prep.setString(1,brandName);
        prep.setString(2,companyName);
        prep.setInt(3,ordered);
        prep.setString(4,description);
        prep.setInt(5,status);

        int count = prep.executeUpdate();

        System.out.println(count > 0);

//        Brand b = null;
//        List<Brand> list = new ArrayList<Brand>();
//        while(rs.next()){
//            b = new Brand(rs.getInt("id"),rs.getString("brand_name"),rs.getString("company_name"),rs.getInt("ordered"),rs.getString("description"),rs.getInt("status"));
//            list.add(b);
//        }
//        System.out.println(list);


        prep.close();
        conn.close();

    }
}
